var mapIds = [330003100, 330003200, 330003300, 330003400, 330003500, 330003600];
var 准备地图 = 330003000;

function init() {}

function setup(c, a) {
    em.setProperty("state", 1);
    em.setProperty("leader", "true");
    var c = em.newInstance("副本_好友故事_旧楼");
    c.setProperty("stage", 0);
    c.initPropArrayRandom("stage", 0, 4, 4);
    c.setProperty("stage_5", 5);
    for (var b = 0; b < mapIds.length; b++) {
        var d = c.setInstanceMap(mapIds[b]);
        d.resetFully();
        d.killAllMonsters(false)
    }
    return c
}

function onPlayerRegistered(c, b) {
    b.setReviveCount(-100);
    var a = parseInt(c.getProperty("stage_1"));
    var d = c.getMapInstance(a);
    b.changeMap(d, d.getPortal(0));
    c.startEventTimer(15 * 60 * 1000)
}

function onPlayerRevived(b, a) {
    return false
}

function onMapChanged(d, c, b) {
    if (mapIds.indexOf(b) < 0) {
        on玩家退场(d, c, false);
        return
    }
    var a = d.getNumberProperty("stage") + 1;
    d.setProperty("stage", a);
    d.setProperty("kill", "0");
    d.setProperty("clear", "0");
    d.setProperty("curMap", b)
}

function onPlayerDisconnected(b, a) {
    on玩家退场(b, a, false);
    return 0
}

function onTimeOut(a) {
    a.getPlayers().forEach(function (b) {
        on玩家退场(a, b, true)
    })
}

function onMonsterKilled(a, b) {
    a.getPlayers().forEach(function (f) {
        var e = a.getNumberProperty("kill") + 1;
        a.setProperty("kill", e);
        var d = f.getMapId();
        if (d == 330003100) {
            if (b == 2700100) {
                f.getAPI().fieldEffect_Clear("monsterPark/clear");
                f.getAPI().getTopMsgFont("10秒后，移动到下一关卡。", 3, 20, 0, 0);
                var c = a.getNumberProperty("stage") + 1;
                var g = a.getNumberProperty("stage_" + c);
                f.scheduleWarpTask(10, 330003100 + 100 * g, 0);
                a.setProperty("clear", 1)
            } else {
                if (e == 30) {
                    f.getAPI().fieldEffect_Clear("monsterPark/specialMonster");
                    f.getAPI().spawnMobLimit(2700100, 1, 975, 43, 1);
                    f.getAPI().fieldEffect_PlayFieldSound("FriendsStory/SpecialMob", 100)
                }
            }
        } else {
            if (d == 330003200) {
                if (b == 2700101) {
                    f.getAPI().fieldEffect_Clear("monsterPark/clear");
                    f.getAPI().getTopMsgFont("10秒后，移动到下一关卡。", 3, 20, 0, 0);
                    var c = a.getNumberProperty("stage") + 1;
                    var g = a.getNumberProperty("stage_" + c);
                    f.scheduleWarpTask(10, 330003100 + 100 * g, 0);
                    a.setProperty("clear", 1)
                } else {
                    if (e == 30) {
                        f.getAPI().fieldEffect_Clear("monsterPark/specialMonster");
                        f.getAPI().spawnMobLimit(2700101, 1, 1180, 43, 1);
                        f.getAPI().fieldEffect_PlayFieldSound("FriendsStory/SpecialMob", 100)
                    }
                }
            } else {
                if (d == 330003300) {
                    if (b == 2700102) {
                        f.getAPI().fieldEffect_Clear("monsterPark/clear");
                        f.getAPI().getTopMsgFont("10秒后，移动到下一关卡。", 3, 20, 0, 0);
                        var c = a.getNumberProperty("stage") + 1;
                        var g = a.getNumberProperty("stage_" + c);
                        f.scheduleWarpTask(10, 330003100 + 100 * g, 0);
                        a.setProperty("clear", 1)
                    } else {
                        if (e == 30) {
                            f.getAPI().fieldEffect_Clear("monsterPark/specialMonster");
                            f.getAPI().spawnMobLimit(2700102, 1, 975, 43, 1);
                            f.getAPI().fieldEffect_PlayFieldSound("FriendsStory/SpecialMob", 100)
                        }
                    }
                } else {
                    if (d == 330003400) {
                        if (b == 2700103) {
                            f.getAPI().fieldEffect_Clear("monsterPark/clear");
                            f.getAPI().getTopMsgFont("10秒后，移动到下一关卡。", 3, 20, 0, 0);
                            var c = a.getNumberProperty("stage") + 1;
                            var g = a.getNumberProperty("stage_" + c);
                            f.scheduleWarpTask(10, 330003100 + 100 * g, 0);
                            a.setProperty("clear", 1)
                        } else {
                            if (e == 30) {
                                f.getAPI().fieldEffect_Clear("monsterPark/specialMonster");
                                f.getAPI().spawnMobLimit(2700103, 1, 1200, 43, 1);
                                f.getAPI().fieldEffect_PlayFieldSound("FriendsStory/SpecialMob", 100)
                            }
                        }
                    } else {
                        if (d == 330003500) {
                            if (b == 2700104) {
                                f.getAPI().fieldEffect_Clear("monsterPark/clear");
                                f.getAPI().getTopMsgFont("10秒后，移动到下一关卡。", 3, 20, 0, 0);
                                var c = a.getNumberProperty("stage") + 1;
                                var g = a.getNumberProperty("stage_" + c);
                                f.scheduleWarpTask(10, 330003100 + 100 * g, 0);
                                a.setProperty("clear", 1)
                            } else {
                                if (e == 30) {
                                    f.getAPI().fieldEffect_Clear("monsterPark/specialMonster");
                                    f.getAPI().spawnMobLimit(2700104, 1, 600, 43, 1);
                                    f.getAPI().fieldEffect_PlayFieldSound("FriendsStory/SpecialMob", 100)
                                }
                            }
                        } else {
                            if (d == 330003600) {
                                if (b >= 2700200 && b <= 2700204) {
                                    f.getAPI().fieldEffect_Clear("monsterPark/clearF");
                                    f.getAPI().addNumberForQuestInfo(33100, "count", 1);
                                    a.setProperty("clear", 1);
                                    f.scheduleOpenNpcTask(3, 1000, "好友故事_旧楼")
                                }
                            }
                        }
                    }
                }
            }
        }
    });
    return 1
}

function onPlayerRevived(b, a) {
    return false
}

function onPartyDisbanded(a) {}

function onPlayerKilled(b, a) {}
var setupTask;

function randomNum(b, a) {
    switch (arguments.length) {
        case 1:
            return parseInt(Math.random() * b + 1, 10);
            break;
        case 2:
            return parseInt(Math.random() * (a - b + 1) + b, 10);
            break;
        default:
            return 0;
            break
    }
}

function initProp(a, b) {
    if (eim.getProperty(a) == null) {
        eim.setProperty(a, b)
    }
}

function initPropArray(a, d, c, e) {
    for (var b = c; b <= e; b++) {
        if (eim.getProperty(a + "_" + b) == null) {
            eim.setProperty(a + "_" + b, d)
        }
    }
}

function on玩家退场(c, b, a) {
    c.disposeIfPlayerBelow(a ? 999 : 0, 准备地图);
    c.getProperties().clear();
    em.setProperty("state", 0);
    em.setProperty("leader", "true");
    c.unregisterPlayer(b)
};